package com.xiaozhi.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Lookup;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * Aware接口:帮我们装配Spring底层的一些组件
 * Bean的功能增强全部都是由BeanPostProcessor + InitializingBean构成
 */

/**
 * Person为什么能把ApplicationContext、MessageSource当成自己的参数传进来
 *   - 通过实现接口的方式自动注入了ApplicationContext、MessageSource。是由BeanPostProcessor后置处理器完成的
 */
// @Component
public class Person implements ApplicationContextAware {
	private String name;
	// @Autowired //依赖的组件是多实例就不能Autowired
	private Cat cat;


	private ApplicationContext applicationContext;
	public Person(){
		System.out.println("Persion对象创建了...");
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		this.applicationContext = applicationContext;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Autowired
	public void setCat(Cat cat) {
		this.cat = cat;
	}

//	@Autowired
//	public void setCat(Cat cat) {
//		this.cat = cat;
//	}

//	@Lookup
	public Cat getCat() {
		return cat;
	}

	@Override
	public String toString() {
		return "Person{" +
				"name='" + name + '\'' +
				'}';
	}


}